import { REQAUTH } from "../../api";
import { SET_CURRENT_USER } from "../../constants";
import jwsDecode from "jwt-decode";
import { storageDel } from "../../utils/storage";

export const login = (data) => {
  return async (dispatch) => {
    const result = await REQAUTH(data);
    dispatch(setCurrentUser(jwsDecode(result.token)));
    return result;
  };
};
export const logout = data => {
  return dispatch => {
    storageDel(data, "sessionStorage");
    dispatch(setCurrentUser({}))
  }
};
export const setCurrentUser = (user) => {
  console.log(user);
  return {
    type: SET_CURRENT_USER,
    user,
  };
};
